/**
 * @(#) IncomeReportProxy.as
 *
 * @date		2010. 01. 17.
 * @version		1.0
 * @author		Goo,Sang Hoi
 * @description	 연말정산  - Proxy
 * 				신용카드 소득공제 신고서
 */
package com.skt.common_hr.yearadjustment.model
{

	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.yearadjustment.YearAdjustmentFacade;
	import com.wcl.utils.DateUtil;
	import com.wcl.utils.NumberUtil;
	import com.wcl.utils.StringUtil;
	
	import flash.net.URLVariables;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	

	public class CreditCardReportProxy extends CommonProxy
	{
		public static const NAME:String = "CreditCardReportProxy";
		public var msgStr:String;
		public var errCode:int;
		public var errText:String;
		public var url:String;
		
		public var card:URLVariables = new URLVariables();
		
		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function CreditCardReportProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function load(pernr:String, year:String):void
		{
			var param:Object = new Object();

			param["I_PERNR"] = pernr;
			param["I_YEAR"] = year;

			loadData("Z_HR_YEA_CREDIT_CARD",param, result, fault);
		}
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			//2013
			errCode = event.result["RETCODE"];
			errText = event.result["RETTEXT"];
			msgStr = event.result["RETTEXT"];
			if(event.result["RETCODE"]==0) {
				url = StringUtil.NVL(event.result["O_PATH"]);
				facade.sendNotification(YearAdjustmentFacade.LOAD_CREDIT_CARD_REPORT_COMPLETE, this);
			}
			else {
				url = "";
				facade.sendNotification(YearAdjustmentFacade.LOAD_CREDIT_CARD_REPORT_FAILED, this);
			}
			
			/* 
			if(retCode==0) {  
				trace( "suss to load Income Report proxy");
				//Export 정보
				parseExport(event);
				//신용카드  정보
				parseCreditCard(event.result.I_CARD);
				
				facade.sendNotification(YearAdjustmentFacade.LOAD_CREDIT_CARD_REPORT_COMPLETE, this);
			}
			else {
				trace( "failed to load Incomde Report: (" +event.result["RETCODE"] + ") "+event.result["RETTEXT"]);
				msgStr = event.result["RETTEXT"];
				facade.sendNotification(YearAdjustmentFacade.LOAD_CREDIT_CARD_REPORT_FAILED, this);
			}
			 */
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			trace("Fault message in Income Report: " + event.fault.faultString);
			msgStr = event.fault.faultString;
			facade.sendNotification(YearAdjustmentFacade.LOAD_CREDIT_CARD_REPORT_FAILED, this);
		}
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		
		/**
		 * 신용카드 소득공제  Export 정보
		 * 
		 * @param
		 * @return 신용카드 소득공제  Export 정보  Value Object
		 */
		private function parseExport(event:ResultEvent):void {
			card["E_ENAME"] = event.result["E_ENAME"];
			card["I_PERNR"] = Variables.yearPernr;
			
//			card["E_BIRDT"] = event.result["E_BIRDT"];
			// common infra에 맞게 수정 2010.12.09 by Shin, YUNWOO
			//card["E_BIRDT"] = DateUtil.toFormatString(event.result["E_BIRDT"] as Date, "YYYY.MM.DD");
			var tmp:Date = DateUtil.stringToDateTime(event.result["E_BIRDT"]);
			card["E_BIRDT"] = DateUtil.toDefaultString(tmp);
			
			card["E_WORKPLACE"] = event.result["E_WORKPLACE"];
			
			//사업자 등록번호
			var bizNo:String = event.result["E_BIZNO"];
			card["E_BIZNO"] = bizNo.substr(0, 3) + "-" + bizNo.substr(3, 2) + "-" +  bizNo.substr(5, 5);
			
			card["E_INCOME"] = NumberUtil.NumberFormat(Number(event.result["E_INCOME"]));
			card["E_LIMIT"] = NumberUtil.NumberFormat(Number(event.result["E_LIMIT"]));
			card["E_OVERUSE"] = NumberUtil.NumberFormat(Number(event.result["E_OVERUSE"]));
			card["E_DEDUCT"] = NumberUtil.NumberFormat(Number(event.result["E_DEDUCT"]));
			card["E_MAX"] = NumberUtil.NumberFormat(Number(event.result["E_MAX"]));
			card["E_CALC_DEDUCT"] = NumberUtil.NumberFormat(Number(event.result["E_CALC_DEDUCT"]));
			
			//신청일자
			var sysDt:Array = DateUtil.toDefaultString(new Date()).split("-");
			card["E_SYS_YEAR"] 	= sysDt[0];
			card["E_SYS_MONTH"] 	= sysDt[1];
			card["E_SYS_DAY"] 	= sysDt[2];
			
			card["E_S01"] =  NumberUtil.NumberFormat(Number(event.result["E_S01"]));
			card["E_S02"] =  NumberUtil.NumberFormat(Number(event.result["E_S02"]));
			card["E_S03"] =  NumberUtil.NumberFormat(Number(event.result["E_S03"]));
			card["E_S04"] =  NumberUtil.NumberFormat(Number(event.result["E_S04"]));
			card["E_S05"] =  NumberUtil.NumberFormat(Number(event.result["E_S05"]));
			card["E_S06"] =  NumberUtil.NumberFormat(Number(event.result["E_S06"]));
			card["E_S07"] =  NumberUtil.NumberFormat(Number(event.result["E_S07"]));
			card["E_S08"] =  NumberUtil.NumberFormat(Number(event.result["E_S08"]));
			card["E_S09"] =  NumberUtil.NumberFormat(Number(event.result["E_S09"]));
			card["E_S10"] =  NumberUtil.NumberFormat(Number(event.result["E_S10"]));
			card["E_S11"] =  NumberUtil.NumberFormat(Number(event.result["E_S11"]));
			
			if(card["E_S01"] == "0") card["E_S01"] = "";
			if(card["E_S02"] == "0") card["E_S02"] = "";
			if(card["E_S03"] == "0") card["E_S03"] = "";
			if(card["E_S04"] == "0") card["E_S04"] = "";
			if(card["E_S05"] == "0") card["E_S05"] = "";
			if(card["E_S06"] == "0") card["E_S06"] = "";
			if(card["E_S07"] == "0") card["E_S07"] = "";
			if(card["E_S08"] == "0") card["E_S08"] = "";
			if(card["E_S09"] == "0") card["E_S09"] = "";
			if(card["E_S10"] == "0") card["E_S10"] = "";
			if(card["E_S11"] == "0") card["E_S11"] = "";
			
			
			
			
			
			
			
			
			//20130101 추가
			card["E_S12"] =  NumberUtil.NumberFormat(Number(event.result["E_S12"]));
			card["E_TRD"] =  NumberUtil.NumberFormat(Number(event.result["E_TRD"]));
			card["E_DEB"] =  NumberUtil.NumberFormat(Number(event.result["E_DEB"]));
			card["E_CARD"] =  NumberUtil.NumberFormat(Number(event.result["E_CARD"]));
			card["E_INCOME"] =  NumberUtil.NumberFormat(Number(event.result["E_INCOME"]));
			card["E_LIMIT"] =  NumberUtil.NumberFormat(Number(event.result["E_LIMIT"]));
			card["E_C1"] =  NumberUtil.NumberFormat(Number(event.result["E_C1"]));
			card["E_C2"] =  NumberUtil.NumberFormat(Number(event.result["E_C2"]));
			card["E_C3"] =  NumberUtil.NumberFormat(Number(event.result["E_C3"]));
			card["E_C4"] =  NumberUtil.NumberFormat(Number(event.result["E_C4"]));
			card["E_C5"] =  NumberUtil.NumberFormat(Number(event.result["E_C5"]));
			card["E_C6"] =  NumberUtil.NumberFormat(Number(event.result["E_C6"]));
			card["E_C7"] =  NumberUtil.NumberFormat(Number(event.result["E_C7"]));
			card["E_C8"] =  NumberUtil.NumberFormat(Number(event.result["E_C8"]));									
			
			
			//20130101 추가
			if(card["E_S12"] == "0") card["E_S12"] = "";
			
			if(card["E_C1"] == "0") card["E_C1"] = "";
			if(card["E_C2"] == "0") card["E_C2"] = "";
			if(card["E_C3"] == "0") card["E_C3"] = "";
			if(card["E_C4"] == "0") card["E_C4"] = "";
			if(card["E_C5"] == "0") card["E_C5"] = "";
			if(card["E_C6"] == "0") card["E_C6"] = "";
			if(card["E_C7"] == "0") card["E_C7"] = "";
			if(card["E_C8"] == "0") card["E_C8"] = "";
			
//			if(card["E_S11"] == "0") card["E_S11"] = "";
//			if(card["E_S11"] == "0") card["E_S11"] = "";
//			if(card["E_S11"] == "0") card["E_S11"] = "";
//			if(card["E_S11"] == "0") card["E_S11"] = "";
//			if(card["E_S11"] == "0") card["E_S11"] = "";
//			if(card["E_S11"] == "0") card["E_S11"] = "";
//			if(card["E_S11"] == "0") card["E_S11"] = "";
		}
		
		/**
		 * 신용카드 소득공제  정보
		 * 
		 * @param
		 * @return 신용카드 소득공제  정보  Value Object
		 */
		private function parseCreditCard(arr:ArrayCollection):void
		{
			for (var i:int = 0; i<arr.length; ++i ){
//				var vo:CreditCardReportVO = new CreditCardReportVO();
				
				card["NATIO" + i.toString()] = arr[i].NATIO;
				card["RELAT" + i.toString()] = arr[i].RELAT;		
				card["ENAME" + i.toString()] = arr[i].ENAME;

				card["BIRDT" + i.toString()] = DateUtil.toFormatString(DateUtil.stringToDateTime(arr[i].BIRDT), "YYYY.MM.DD");		
				card["NAM_TOT" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].NAM_TOT));
				card["OAM_TOT" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].OAM_TOT));	
				card["NAM_CARD" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].NAM_CARD));		
				card["OAM_CARD" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].OAM_CARD));			
				card["NAM_GIRO" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].NAM_GIRO));			
				card["OAM_GIRO" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].OAM_GIRO));		
				card["NAM_CASH" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].NAM_CASH));		
				card["OAM_CASH" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].OAM_CASH));		
				card["NAM_BIZ" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].NAM_BIZ));			
				card["OAM_BIZ" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].OAM_BIZ));			
				card["NAM_OCARD" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].NAM_OCARD));		
				card["OAM_OCARD" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].OAM_OCARD));
				
				//20130101 추가
				card["NAM_TRD" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].NAM_TRD));		
				card["OAM_TRD" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].OAM_TRD));						
				
				card["NAM_CARD_TOT" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].NAM_CARD_TOT));		
				card["OAM_CARD_TOT" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].OAM_CARD_TOT));	
				card["NAM_GIRO_TOT" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].NAM_GIRO_TOT));	
				card["OAM_GIRO_TOT" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].OAM_GIRO_TOT));	
				card["NAM_CASH_TOT" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].NAM_CASH_TOT));	
				card["OAM_CASH_TOT" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].OAM_CASH_TOT));	
				card["NAM_BIZ_TOT" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].NAM_BIZ_TOT));	
				card["OAM_BIZ_TOT" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].OAM_BIZ_TOT));	
				card["NAM_OCARD_TOT" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].NAM_OCARD_TOT));		
				card["OAM_OCARD_TOT" + i.toString()] = NumberUtil.NumberFormat(Number(arr[i].OAM_OCARD_TOT));	
				
			}

			card["COUNT"] = arr.length.toString();	
			
		}

		
		
		
	}
}